package com.hts.spring06.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.logging.Logger;


@Component
@Aspect
public class LogAroundAspect {
    Logger logger = Logger.getLogger("DynamicProxy");


    // 单独定义一个切入点  cut：剪    point ：点
    @Pointcut("execution(* com.hts.spring06.service.*.*(..))")
    public void pointCut() {

    }

    /*
       around: 周围, 环绕
       joinPoint: 目标对象
     */
    @Around("pointCut() ")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        try {
            //1 .参数
            Object[] args = joinPoint.getArgs();
            logger.info("环绕增强:参数" + args[0]);

            Object result = joinPoint.proceed(args);// 放行,继续执行
            logger.info("环绕增强:返回值" + result);
            return result;
        }catch (Exception e){
            logger.info(e.getMessage());
            logger.warning("出异常了");
        }

        return null;

    }

}
